import { request } from '@vipl520/utils'
const path = '/' + import.meta.env.VITE_BASE_ADDON_NAME + '/crud/'

export function saveDesign(designData, crud_id = 0) {
  return request({
    url: path + 'saveDesign',
    method: 'post',
    data: { designData, crud_id }
  })
}

export function generate(designData, zip = 0) {
  return request({
    url: path + 'generate',
    method: 'post',
    data: { designData, zip }
  })
}

export function updateSql(designData) {
  return request({
    url: path + 'updateSql',
    method: 'post',
    data: { designData }
  })
}

export function getRemoteTableOption(addon_name) {
  return request({
    url: path + 'getRemoteTableOption',
    method: 'post',
    data: { addon_name }
  })
}

export function getRemoteFieldOption(table_name, addon_name) {
  return request({
    url: path + 'getRemoteFieldOption',
    method: 'post',
    data: { table_name, addon_name }
  })
}

export function getList(page, size, search) {
  return request({
    url: path + 'index',
    method: 'get',
    params: { page, size, search, order: 'id desc' }
  })
}

export function getForm(id) {
  return request({
    url: path + 'getForm',
    method: 'post',
    data: { id }
  })
}

// 删除
export function del(id) {
  return request({
    url: path + 'delete',
    method: 'post',
    data: { id }
  })
}

export function getById(id) {
  return request({
    url: path + 'getById',
    method: 'post',
    data: { id }
  })
}

// 清空
export function clear() {
  return request({
    url: path + 'clear',
    method: 'post'
  })
}

// 覆盖文件
export function overwriteFile(fileData, addon_name) {
  return request({
    url: path + 'overwriteFile',
    method: 'post',
    data: { fileData, addon_name }
  })
}
